package com.ruoyi.hospital.controller.coupon;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.coupon.CouponRecord;
import com.ruoyi.hospital.service.coupon.ICouponRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 领券记录Controller
 * 
 * @author wendao
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/hospital/couponRecord")
public class CouponRecordController extends BaseController
{
    @Autowired
    private ICouponRecordService couponRecordService;

    /**
     * 查询领券记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:couponRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CouponRecord couponRecord)
    {
        startPage();
        List<CouponRecord> list = couponRecordService.selectCouponRecordList(couponRecord);
        return getDataTable(list);
    }

    /**
     * 导出领券记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:couponRecord:export')")
    @Log(title = "领券记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CouponRecord couponRecord)
    {
        List<CouponRecord> list = couponRecordService.selectCouponRecordList(couponRecord);
        ExcelUtil<CouponRecord> util = new ExcelUtil<CouponRecord>(CouponRecord.class);
        util.exportExcel(response, list, "领券记录数据");
    }

    /**
     * 获取领券记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:couponRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(couponRecordService.selectCouponRecordById(id));
    }

    /**
     * 新增领券记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:couponRecord:add')")
    @Log(title = "领券记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponRecord couponRecord)
    {
        return toAjax(couponRecordService.insertCouponRecord(couponRecord));
    }

    /**
     * 修改领券记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:couponRecord:edit')")
    @Log(title = "领券记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponRecord couponRecord)
    {
        return toAjax(couponRecordService.updateCouponRecord(couponRecord));
    }

    /**
     * 删除领券记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:couponRecord:remove')")
    @Log(title = "领券记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(couponRecordService.deleteCouponRecordByIds(ids));
    }
}
